var a;
		var b;
		//var xtId = '${xtId}';
		//var formaWin = '${formaWin}';
		$(function(){
			a = document.documentElement.clientHeight - 110;
		 	b = document.documentElement.clientWidth - 20;
			
			//改变选题的时候
			//$('#xtList').change(function(){xtChange();});
			
			
			
			//加载选题下拉框
			//loadXTSelect();
			
		});
		var flowNodeArr;
		var execState;
		var xtArr;
		var operators;
		var bumenArr;
		function loadXTDzSource(){
			$.ajax({
				url:'../../dz/queryDzList',
				type:'post',
				data:{dzIds:'flow_nodes;exec_state;dz_xt;dz_operators;dz_bumen'},
				success:function(data){
					//xtType 选题类型     author 作者  station 站点 oparator 用户
					flowNodeArr = data[0];
					execState = data[1];
					xtArr = data[2];
					operators = data[3];
					bumenArr = data[4];
				}
			});
		}
		
		function flowBumenFormatter(value){
			for(var i=0; i<bumenArr.length; i++){
				if (bumenArr[i].ID == value) return bumenArr[i].NAME;
			}
			return value;
		}
		
		function flowNodeFormatter(value){
			for(var i=0; i<flowNodeArr.length; i++){
				if (flowNodeArr[i].ID == value) return flowNodeArr[i].NAME;
			}
			return value;
		}
		
		function flowOperatorsFormatter(value){
			for(var i=0; i<operators.length; i++){
				if (operators[i].ID == value) return operators[i].NAME;
			}
			return value;
		}
		
		function stateFormatter(value){
			if(value=='')return '未执行';
			for(var i=0; i<execState.length; i++){
				if (execState[i].ID == value) return execState[i].NAME;
			}
			return value;
		}
		
		function flowXTFormatter(value){
			for(var i=0; i< xtArr.length; i++){
				if (xtArr[i].ID == value)
				return xtArr[i].NAME;
			}
			return value;
		}
		
		function loadXTSelect(){
					$.ajax({
						url:'../../dz/queryDz',
						data:{'dzId':'dz_xt'},
						type:"post",
						success:function(data){
							var optionHTML = "<option value=''></option>";
							for(var i = 0; i < data.rows.length; i++){
								optionHTML+= "<option value='"+data.rows[i].ID+"'>"+data.rows[i].NAME+"</option>"
							}
							$('#xtList').html(optionHTML);
							if(xtId != ''){
							//	alert(xtId);
								$('#xtList').val(xtId);
								xtChange();
							}
						}
					});
		}
		
		
		//将节点初始化
		function initInsertLink(){
			$('#InsertLink').window({  
			    height:document.documentElement.clientHeight,
			    width:document.documentElement.clientWidth,
			    title:'环节列表',  
			    modal:true  
			});
			$('#InsertLink').window('close');
			loadInsertLinkData();
		}
		
		//加载所有环节数据和 页面按钮
		function loadInsertLinkData(){
			$.ajax({
					type:'post',
					url:'../../framework/buttonsListC',
					data:{'butnId':'XTPlanEtALink'},
					success:function(data){
						if(data == ""){
							alert("按钮数据为空");
						}else{
							var buttons = data;
							var butHTML = "";
							for(var i = 0; i < buttons.length; i++){
								butHTML += formatButtons(buttons[i]);
							}
							$("#LINKBUTTONS").html(butHTML);
							$.parser.parse("#LINKBUTTONS");  //重新编译按钮
						}
					}
				});
			//初始化环节数据
			loadHJDategrid();
		}
		
		// 加载环节数据表格
		function loadHJDategrid(){
			$.ajax({
				type:'post',
				url:'../../framework/listQueryJson',
				data:{'dsId':'InsertLink','colId':'InsertLink','execFlag':''},
				success:function(data){
					if(data==""){
						alert("数据为空");
					}else{
						//给datagrid赋列值，没有数据
						mdatagridHJ(data);
						//加载数据
						//查询选题计划
						$.ajax({
							url:'../../framework/loadData',
							data:{dsId:"InsertLink",config:'',page:1,rows:1000},
							success:function(queryJson){
								$('#LINKDATALIST').datagrid("loadData", queryJson);
							}
						});
					}
				}
			});
		}
		
		// 加载环节Datagrid
		function mdatagridHJ(data){ //传入的是queryJson 里面就有columns和rows
			var lastIndex;
			$('#LINKDATALIST').datagrid({
				iconCls:'icon-save',
				height:a,
				width:b,
				striped: true,				 
				collapsible:true,
				autoRowHeight: false,		
				sortOrder: 'desc',
				remoteSort: false,
				frozenColumns:[[
	                {field:'ck',checkbox:true}
				]],
				columns:[[]],
				rownumbers:true,
				singleSelect:true,
				onDblClickRow:function(rowIndex,rowData){
					
				}
			});
			var dataGrid = $('#LINKDATALIST');
			dataGrid.datagrid(jointColumn(data.columns));//根据配置选项，生成datagrid  
		}
		
		// 加载选题计划数据表格
		function loadXTPlanDategrid(){
//			$.ajax({
//				type:'post',
//				url:'../../framework/listQueryJson',
//				data:{'dsId':'XTPlan','colId':'XTPlan','execFlag':''},
//				success:function(data){
//					if(data==""){
//						alert("数据为空");
//					}else{
//						//给datagrid赋列值，没有数据
//						mdatagridPL(data);
//						
//					}
//				}
//			});
			$.ajax({
                type:'post',
                url:'../../framework/loadColumnsU',
                data:{'colId':'XTPlan','type':'4'},
                success:function(data){
                    if(data ==""){
                        alert("数据为空");
                    }else{
                        producePage(data,'PLAN_DATALIST','4','');
                			$('#PLAN_DATALIST').datagrid({
                				onDblClickRow:function(rowIndex,rowData){
                					//双击数据  弹出环节点窗口
                					//alert('doub');
                				},onClickRow:function(rowIndex, rowData){
                					dbRowIndex = rowIndex;
                				},onClickCell:function(rowIndex,field,value){
                					//双击单元格
                					alert(rowIndex);
                				}
                			});
                		}
                }
			});
		}
		
		//初始化选题计划Datagrid
		function mdatagridPL(data){ //传入的是queryJson 里面就有columns和rows
			var lastIndex;
			$('#PLAN_DATALIST').datagrid({
				iconCls:'icon-save',
				height:a,
				width:b,
				striped: true,				 
				collapsible:true,
				autoRowHeight: false,		
				sortOrder: 'desc',
				remoteSort: false,
				columns:[[]],
				idField:'MANAGE_ID',
				rownumbers:true,
				singleSelect:true,
				onDblClickRow:function(rowIndex,rowData){
					//双击数据  弹出环节点窗口
					
				}
			});
			var dataGrid = $('#PLAN_DATALIST');
			dataGrid.datagrid(jointColumn(data.columns));//根据配置选项，生成datagrid  
			
		}
//		//初始化选题计划Datagrid
//		function mdatagridPL(data){ //传入的是queryJson 里面就有columns和rows
//			var lastIndex;
//			$('#PLAN_DATALIST').datagrid({
//				iconCls:'icon-save',
//				height:a,
//				width:b,
//				striped: true,				 
//				collapsible:true,
//				autoRowHeight: false,		
//				sortOrder: 'desc',
//				remoteSort: false,
//				columns:[[]],
//				idField:'MANAGE_ID',
//				rownumbers:true,
//				singleSelect:true,
//				onDblClickRow:function(rowIndex,rowData){
//					//双击数据  弹出环节点窗口
//					//alert('doub');
//				},onClickRow:function(rowIndex, rowData){
//					dbRowIndex = rowIndex;
//				},onClickCell:function(rowIndex,field,value){
//					//双击单元格
//					alert(rowIndex);
//				}
//			});
//			var dataGrid = $('#PLAN_DATALIST');
//			dataGrid.datagrid(jointColumn(data.columns));//根据配置选项，生成datagrid  
//			
//		}

		//加载选题计划页面按钮
		function loadXTPlanButn(){
			$.ajax({
					type:'post',
					url:'../../framework/buttonsListC',
					data:{'butnId':'XTPlanEtPS;XTPlanEtP;XTPLupNode'},
					success:function(data){
						if(data == ""){
							alert("按钮数据为空");
						}else{
							var buttons = data;
							var butHTML = "";
							for(var i = 0; i < buttons.length; i++){
								butHTML += formatButtons(buttons[i]);
							}
							$('#PLAN_BUTTONS').html(butHTML);
							$.parser.parse('#PLAN_BUTTONS');  //重新编译按钮
						}
					}
				});
		}
		
		//加载选题计划
		function xtChange(){
			//查询选题计划
			var configStr = "XT_ID-"+$('#xtList').val();
			if(configStr == '00')return;
			//加载shuju
			$.ajax({
				url:'../../framework/loadData?page=1&rows=1000',
				data:{dsId:"XTPlan",config:configStr},
				success:function(queryJson){
					$('#PLAN_DATALIST').datagrid("loadData", queryJson);
					//$('#PLAN_DATALIST').datagrid({url:queryJson.url});
				}
			});
		}
		//添加环节点方法*******************************************************************************
		var parentFlowId = 0;//插入环节还是父节点，状态标志
		var dbRowIndex = -1;
		
		//点击插入环节按钮
		function addPlanNodes(){
			if(checkIsSelect('PLAN_DATALIST',1) !=0 )return;
			$('#InsertLink').window('open');
			if(parentFlowId != 1){
				$('#LINKDATALIST').datagrid('clearSelections');
			}
			$('#LINKDATALIST').datagrid({singleSelect:false});
			parentFlowId = 1;//插入环节标志位
		}
		//点击插入父节点
		function insertParentPlan(){
			if(checkIsSelect('PLAN_DATALIST',2) != 0 )return;
			$('#InsertLink').window('open');
			if(parentFlowId != 2){
				$('#LINKDATALIST').datagrid('clearSelections');
			}
			$('#LINKDATALIST').datagrid({singleSelect:true});
			parentFlowId = 2;//插入父节点标志位
		}
		
		//检查是否选中一行选题计划
		function checkIsSelect(dataDiv,flagValue){
			if($('#xtList').val() == '' || $('#xtList').val() == '00'){
				$.messager.alert('提示框','请先选择编辑选题','info');
				return 1;
			}
			if(flagValue == 2){//插入父环节检查
				if($('#'+dataDiv).datagrid('getSelected') == null){
					$.messager.alert('提示框','请选择一行数据','info');
					return 2;
				}
			}
			return 0;
		}
		
		//确定添加环节点
		function confirmation(){
			$('#InsertLink').window('close');
			if(parentFlowId == 1){//为1 则默认取节点
				var selRows = $('#LINKDATALIST').datagrid('getSelections');
				var oldRows = $('#PLAN_DATALIST').datagrid('getRows');
				for(var i = 0; i < selRows.length; i++){
					for(var j = 0; j < oldRows.length; j++){
						if(oldRows[j].FLOW_ID ==  selRows[i].FLOW_ID){
							//var mas = flowNodeFormatter(oldRows[j].FLOW_ID);
							$.messager.alert('提示',"【"+flowNodeFormatter(oldRows[j].FLOW_ID)+'】环节重复,已有该环节,请重新选择','info');
							return;
						}
					}
					$('#PLAN_DATALIST').datagrid('appendRow',{
						END_DATE:'',
						EXECSTATE:'',
						BEGIN_DATE:'',
						DUTY_BUMEN:'',
						DUTY_MAN:'',
						FLOW_ID:selRows[i].FLOW_ID,
						PARENT_FLOW_ID:'',
						SORT_NUMBER:'',
						XT_ID:$('#xtList').val()
					});
				}
			}else if(parentFlowId == 2){//为2 则添加父节点
				var selParRow = $('#LINKDATALIST').datagrid('getSelected');
				if(selParRow == null){$.messager.alert('提示','请选择一个父环节点');return;};
				var selRow = $('#PLAN_DATALIST').datagrid('getSelected');
				if(selRow == null)return;
				selRow.PARENT_FLOW_ID = selParRow.FLOW_ID+"";
				$('#PLAN_DATALIST').datagrid('refreshRow', dbRowIndex);
			}
		}
		
		//关闭环节点列表
		function existWindows(){
			$('#InsertLink').window('close');
		}
		//保存选题计划
		function saveFlowMange(){
			var rows = $('#PLAN_DATALIST').datagrid('getRows');
			var flowNodes = new Array();
			var xtListId = $("#hideXTId").val();
			for(var i = 0; i < rows.length; i++){
								flowNodes[i] = {
								'manageId':rows[i].MANAGE_ID,
								'xtId':xtListId,
								'flowId':rows[i].FLOW_ID,
								'parentFlowId':rows[i].PARENT_FLOW_ID,
								'sortNumber':rows[i].SORT_NUMBER,
								'execstate':rows[i].EXECSTATE,
								'inputMan':rows[i].INPUT_MAN,
								'inputDate':rows[i].INPUT_DATE,
								'dutyMan':rows[i].DUTY_MAN,
								'dutyBumen':rows[i].DUTY_BUMEN,
								'beginDate':rows[i].BEGIN_DATE,
								'endDate':rows[i].END_DATE,
								'lastModDate':rows[i].LAST_MOD_DATE,
								'djId':rows[i].DJ_ID,
								'memo':rows[i].MEMO};
			}			
			var flowNodesList = {};
			flowNodesList = flowNodes;
			$.ajax({
				 url:'../../node/saveFlowNodes',
				 type:'post',
                 contentType: "application/json;charset=utf-8",
				 data:JSON.stringify(flowNodesList),
				 dataType: "json",
				 success:function(data){
				 	if(data.msg == 'success'){
				 		$.messager.alert('提示框','保存成功','info');
				 	}else{
				 		$.messager.alert('错误提示框',data.msg,'error');
				 	}
				 		$('#PLAN_DATALIST').datagrid('reload');
				 }
			});
		}
		
		//删除父环节
		function deleteParentPlan(){
			 var selRow = $('#PLAN_DATALIST').datagrid('getSelected');
			if(selRow == null){$.messager.alert('提示','请选择一条环节点记录');return;};
			 $.messager.confirm('提示','确定删除父环节?', function(btn2){
							    //点击确定则保存,否则取消
								    if (btn2) {
								    	selRow.PARENT_FLOW_ID = "";
										$('#PLAN_DATALIST').datagrid('refreshRow', dbRowIndex);
								    }
								});
		}
		
		//删除环节
		function deleteNode(){
			var selRow = $('#PLAN_DATALIST').datagrid('getSelected');
			if(selRow == null){$.messager.alert('提示','请选择一条环节点记录','info');return;}
			$.messager.confirm('提示','确定删除环节?', function(btn2){
			    //点击确定则保存,否则取消
			    if (btn2) {
			    	$.ajax({
			    		url:'../../node/deleteFlowNodes',
			    		data:{managerId:selRow.MANAGE_ID},
			    		success:function(data){
			    			if(data.msg == 'delsuccess'){
						    	$('#PLAN_DATALIST').datagrid('deleteRow', dbRowIndex);
								$('#PLAN_DATALIST').datagrid('acceptChanges','deleted');
			    			}else{
			    				$.messager.alert("错误提示",data.msg,'error');
			    			}
			    		}	
			    	});
			    }
			});
		}
		
		//修改选题环节  信息的  责任人、责任部门等列
		function showPlanNodeInfo(){
			var divName='upTopicPlanTb';//条件字段
			var selRow = $('#PLAN_DATALIST').datagrid('getSelected');
			if(selRow == null){$.messager.alert('提示','请选择一条环节点记录','info');return;}
			var rowObj = selRow;
			
			if(addYWTab('costDialog',"修改选题计划环节","<div style='padding:20px;'><div id='UPTOPICBUT'></div><form id='upTopicForm'><table id='upTopicPlanTb'></table></form></div>")!=1){
				//加载字段\按钮
				$.ajax({
					type:'post',
					url:'../../framework/columnList',
					data:{'colId':'XTPlan'},
					success:function(data){
						if(data ==""){
							alert("字段数据为空");
						}else{
							//请求一个组织列的方法
							clons = data;
							makeColumns(clons,divName);
							$.ajax({
								type:'post',
								url:'../../framework/buttonsListC',
								data:{'butnId':'XTPLupSave'}, //XTupSave;XTsaveS 
								success:function(data){
									if(data == ""){
										alert("按钮数据为空");
									}else{
										var buttons = data;
										var butHTML = "";
										for(var i = 0; i < buttons.length; i++){
											butHTML += formatButtons(buttons[i]);
										}
										$('#UPTOPICBUT').html(butHTML);
										$.parser.parse('#UPTOPICBUT');  //重新编译界面
									}
								}
							});
							//加载对照信息
							var dzIdstr = serializeEDIType("upTopicPlanTb");
							$.ajax({
								url:'../../dz/queryDzList',
								type:'post',
								data:{dzIds:dzIdstr},
								success:function(data){
										//下拉框
										fillSelect(divName,data);
										fillInfo(divName,rowObj);
										//将部分字段变灰
										readOnlyPart(divName);
								}
							});
						}
					}
				});
			}else{
				//填充记录
				fillInfo(divName,rowObj);
				readOnlyPart(divName);
			}
		}
		//修改选题计划详情 (前端效果)
		function updateXTPL(){
			var selRow = $('#PLAN_DATALIST').datagrid('getSelected');
			if(selRow == null)return;
			selRow.FLOW_ID = $('#upTopicForm select[coluname=FLOW_ID]').val();
			selRow.PARENT_FLOW_ID = $('#upTopicForm select[coluname=PARENT_FLOW_ID]').val();
			selRow.EXECSTATE = $('#upTopicForm select[coluname=EXECSTATE]').val();
			selRow.SORT_NUMBER = $('#upTopicForm input[coluname=SORT_NUMBER]').val();
			selRow.DUTY_MAN = $('#upTopicForm select[coluname=DUTY_MAN]').val();
			selRow.DUTY_BUMEN = $('#upTopicForm select[coluname=DUTY_BUMEN]').val();
			selRow.MEMO = $('#upTopicForm input[coluname=MEMO]').val();
			$('#PLAN_DATALIST').datagrid('refreshRow', dbRowIndex);
			//关闭tab
			$('#costDialog').tabs('close','修改选题计划环节');
		}